package com.yztstudy.Listener;

import com.yztstudy.Service.CartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 监听RabbitMQ的消息
 */

@Component
public class CartRabbitMQListener {

    @Autowired
    private CartService cartService;

    /**
     * TODO 监听clear.queue消息队列，清空指定的购物车数据
     * @param cartIds 购物车的主键集合
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "clear.queue"), exchange = @Exchange(value = "topic.ex"), key = "clear.cart"))
    public void clear(List<Integer> cartIds)
    {
        // TODO 1.直接清空购物车中的数据
        cartService.clearIds(cartIds);
    }
}
